package eu.szemraj.utils {

    public class Allocator {

        protected var _type:Class;
        protected var _cache:Array;
        protected var _index:int;

        public function Allocator( type:Class = null ) {
        	
        	
            init( type == null ? Object : type );
        }

        public function getObject( ...constructorParams ):* {
        	
            if( _cache[ _index ] == null ) {
        		
                _cache[ _index ] = new _type( constructorParams );
            }
            return _cache[ _index ];
        }

        public function release():void {
        	
            _cache = [];
            _index = 0;
        }

        public function reset():void {
        	
            _index = 0;
        }

        private function init( type:Class ):void {
        	
            _type = type;
            _cache = [];
            _index = 0;
        }
    }
}
